package cn.itsource._05topics;




import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class HelloRabbitmq {
    public static final String EXCHANGEDECLARE_TOPICE = "EXCHANGEDECLARE_TOPICE";
    public static void main(String[] args) throws IOException, TimeoutException {
        // 创建连接
        ConnectionFactory factory = new ConnectionFactory();
        Connection connection = factory.newConnection();
        // 创建通道
        Channel channel = connection.createChannel();
        // 创建交换机，第三个参数交换机是否持久化
        channel.exchangeDeclare(EXCHANGEDECLARE_TOPICE, BuiltinExchangeType.TOPIC,true);
        // 发送消息,routerKey为空因为只要绑定交换机的都发送消息
        channel.basicPublish(EXCHANGEDECLARE_TOPICE, "direct1.ddd", MessageProperties.PERSISTENT_TEXT_PLAIN, "hello,direct1.*".getBytes());
        channel.basicPublish(EXCHANGEDECLARE_TOPICE, "error.aaa", MessageProperties.PERSISTENT_TEXT_PLAIN, "hello,error*".getBytes());
        System.out.println("发送完成");
    }
}
